<cfcomponent>
	<cffunction name="mainmenu" access="public" returntype="void" output="yes" hint="Shows the main menu">
    	<cfinvoke method="getmainmenu" returnvariable="qmenu">
        <cfoutput query = "qmenu">       
        <cfset showmenuitem = 1>
		<cfif len(trim(qmenu.component)) GT 0 OR len(trim(qmenu.doc)) GT 0>
        	<cfif NOT qmenu.component IS 'login' AND NOT qmenu.component IS 'signout'>
        	<cfinvoke component="cfcs.admin.admin" 
            	method="checkpermissions" 
                userlevel="#request.userlevel#"
                userid="#request.id#" 
                c="#qmenu.component#" 
                a="#qmenu.action#" 
                scriptname="#qmenu.doc#" 
                returnvariable="showmenuitem" />
        	</cfif>
		</cfif>
		<cfif showmenuitem GT 0>
        <div id="button_container" <cfif qmenu.component IS 'signout'>style="padding-top: 40px;"</cfif>>
        <cfif len(trim(qmenu.menu)) GT 0>
        	<cfset linkref = '#request.absoluteadminpath#index.cfm?c=menus&menuid=#qmenu.menu#'>
        </cfif>
        <cfif len(trim(qmenu.component)) GT 0>
        	<cfif len(trim(qmenu.action)) IS 0>
				<cfset linkref = '#request.absoluteadminpath#index.cfm?c=#qmenu.component#'>
			<cfelse>
	            <cfset linkref = '#request.absoluteadminpath#index.cfm?c=#qmenu.component#&a=#qmenu.action#'>
            </cfif>
        </cfif>
        <cfif len(trim(qmenu.doc)) GT 0>
        	<cfset linkref = '#request.absoluteadminpath#/docs/#qmenu.doc#'>
        </cfif>
        <a href = "#linkref#" target="#target#">
        <img border="0" class="menubuttons" src="#request.absoluteadminpath#images/mainmenu/#icon_off#" onmouseover="this.src = '#request.absoluteadminpath#images/mainmenu/#icon_on#'; return overlib('#tooltip#', WIDTH, 100, HEIGHT, 20, OFFSETX, 20, OFFSETY, -10, BGCOLOR, '##FFFFFF', FGCOLOR, '##000000', TEXTCOLOR, '##FFFFFF', TEXTFONT, 'Arial', TEXTSIZE, '12pt', CELLPAD, 6);" onmouseout="this.src = '#request.absoluteadminpath#images/mainmenu/#icon_off#'; return nd();" height="36" />
        </a>
		</div>
        </cfif>
        </cfoutput>
	</cffunction>
    
    <cffunction name="getmainmenu" access="public" returntype="query" hint="Creates a query for the main menu">
        <cffile action="read" file="#request.basepath#admin/menus/#request.language#/main.xml" variable="readxml">
        <cfset menuxml = XmlParse(readxml)>	
		<cf_xmlq name = "qmainmenu" xpath = "/menuitems/menuitem" xml = "#menuxml#"> 
        <cfquery name="qmainmenu" dbtype="query">
        SELECT * FROM qmainmenu
        ORDER BY orderval ASC
        </cfquery>
        <cfreturn qmainmenu>
    </cffunction>

	<cffunction name="adminmenus" access="public" returntype="void" output="yes" hint="Shows an admin menu">
    	<cfargument name="menuid" type="string" required="yes" hint="name of menu being called (must match xml file name without the .xml on the end)">
		<cfargument name="lang" default="#request.defaultlang#" required="no" hint="language">
        
        <cfif fileexists('#request.basepath#admin/menus/#lang#/#menuid#.xml')>
	    	<cfinvoke method="getmenu" menuid="#menuid#" returnvariable="qmenu"  />
            <div style="width: 100%;">
            <cfoutput><h2>#ucase(menuid)#</h2></cfoutput>
            <cfoutput query="qmenu">
			<cfset showmenuitem = 1>
            
			<cfif len(trim(qmenu.component)) GT 0 OR len(trim(qmenu.doc)) GT 0>
            <cfif NOT qmenu.component IS 'login' AND NOT qmenu.component IS 'signout'>
                <cfinvoke component="cfcs.admin.admin" 
                    method="checkpermissions" 
                    userlevel="#request.userlevel#" 
                    userid="#request.id#" 
                    c="#qmenu.component#" 
                    a="#qmenu.action#" 
                    scriptname="#qmenu.doc#" 
                    returnvariable="showmenuitem" />
			</cfif>
			</cfif>
        	
            <cfif showmenuitem GT 0>
			<cfif len(trim(qmenu.menu)) GT 0>
                <cfset linkref = '#request.absoluteadminpath#index.cfm?c=menus&menuid=#qmenu.menu#'>
            </cfif>
            <cfif len(trim(qmenu.component)) GT 0>
				<cfif len(trim(qmenu.action)) IS 0>
                    <cfset linkref = '#request.absoluteadminpath#index.cfm?c=#qmenu.component#'>
                <cfelse>
                    <cfset linkref = '#request.absoluteadminpath#index.cfm?c=#qmenu.component#&a=#qmenu.action#'>
                </cfif>
            </cfif>
            <cfif len(trim(qmenu.doc)) GT 0>
                <cfset linkref = '#request.absoluteadminpath#/docs/#qmenu.doc#'>
            </cfif>            
            <div id="sys_menu" onMouseUp="window.location.href = '#linkref#';">
            <div id="menu_image"><img src="#request.absoluteadminpath#images/icons/#icon#" width="48" height="48" align="absmiddle" style="padding-right: 10px;"></div>
            <div><span id = "menu_title">#title#</span><br>
            <span id = "menu_info">#info#</span>
            </div>
            </div>
            </cfif><!---end if showmenuitem GT 0--->        
            </cfoutput>
            </div>
        <cfelse>
			<cfoutput>The menu #menuid# does not appear to exist for ths installation.  The XML file is missing.</cfoutput>
        </cfif>        	
	</cffunction>

	<cffunction name="admintopmenus" access="public" returntype="void" output="yes" hint="Shows an admin horizontal menu">
		<cfargument name="menuname" default="none" hint="name of the menu file (without extention)" required="yes">
		<cfargument name="c" default="none" hint="name of the menu file (without extention)" required="yes">
                
        <cfinvoke method="gettopmenu" c="#c#" menuname="#menuname#" returnvariable="qmenu"  />
        <div id="component_menus">
        <cfloop query="qmenu">
        <cfif len(trim(qmenu.url)) GT 0>
        <cfinvoke component="cfcs.common.buttons" method="show" btext="#qmenu.title#" tooltip="#qmenu.tooltip#" url="#qmenu.url#" folder="#iconfolder#" img="#icon#" />
        </cfif>
        <cfif len(trim(qmenu.js)) GT 0>
        <cfinvoke component="cfcs.common.buttons" method="show" btext="#qmenu.title#" tooltip="#qmenu.tooltip#" jscript="#qmenu.js#" folder="#iconfolder#" img="#icon#" />
        </cfif>
		</cfloop>
        <div class="clear"></div>
        </div>
	</cffunction>    

    <cffunction name="getmenu" access="public" returntype="query" hint="gets a menus info">
    	<cfargument name="menuid" type="string" required="yes" hint="the name of the menu being called">
        <cffile action="read" file="#request.basepath#admin/menus/#request.language#/#menuid#.xml" variable="readxml">
        <cfset menuxml = XmlParse(readxml)>	
		<cf_xmlq name = "qmenu" xpath = "/menuitems/menuitem" xml = "#menuxml#">
        <cfquery name="qmenu" dbtype="query">
        SELECT * FROM qmenu
        ORDER BY orderval ASC
        </cfquery>
        <cfreturn qmenu>
    </cffunction>
   
    <cffunction name="gettopmenu" access="public" returntype="query" hint="gets a menus info">
    	<cfargument name="c" type="string" required="yes" hint="componet name">
		<cfargument name="menuname" type="string" required="yes" hint="menu file name (without extention)">
        <cfif fileexists('#request.adminpath#components/#c#/menu/#request.language#/#menuname#.xml')>
	        <cffile action="read" file="#request.adminpath#components/#c#/menu/#request.language#/#menuname#.xml" variable="readxml">
		<cfelse>
			<cfif fileexists('#request.adminpath#components/#c#/menu/#request.language#/#menuname#.xml')>
                <cffile action="read" file="#request.adminpath#components/#c#/menu/#request.language#/#menuname#.xml" variable="readxml">
            </cfif>
		</cfif>
		<cfif isdefined('readxml')>
	        <cfset menuxml = XmlParse(readxml)>	
			<cf_xmlq name = "qmenu" xpath = "/menuitems/menuitem" xml = "#menuxml#">
            <cfquery name="qmenu" dbtype="query">
            SELECT * FROM qmenu
            ORDER BY orderval ASC
            </cfquery>
		<cfelse>
        	<cfset qmenu = querynew("title,tooltip,url,js,iconfolder,icon,orderval")>
        </cfif>
        <cfreturn qmenu>
    </cffunction>   
</cfcomponent>